let initialState = {
    token: '',
}

export default function reducer(state = initialState, action: any) {
    // 1. 深拷贝
    let newstate = JSON.parse(JSON.stringify(state))

    // 2.判断action类型
    // token
    if (action.type == 'SAVE_TOKEN') {
        newstate.token = action.payload
    } else if (action.type == 'REMOVE_TOKEN') {
        newstate.token = ''
    }

    // 3.返回全新的state
    return newstate
}